//
//  M1IntroduceMyselfCell.m
//  NewMarryU
//
//  Created by Cedar on 2018/7/16.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1IntroduceMyselfCell.h"

@implementation M1IntroduceMyselfCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self m1_createUI];
    }
    return self;
}

- (void)m1_allAction:(UIButton *)sender{
    if (self.m1_upLoad) {
        self.m1_upLoad();
    }
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
}

-(void)m1_loadText:(NSString *)text unIntroduce:(BOOL)unIntroduce{
    _m1_title.text = text;
    CGSize size = [text boundingRectWithSize:CGSizeMake(SCREENWIDTH - 46, MAXFLOAT)
                                      options: NSStringDrawingUsesLineFragmentOrigin
                                   attributes: [NSDictionary dictionaryWithObjectsAndKeys:m1_font(15), NSFontAttributeName, nil]
                                      context: nil].size;
    _m1_title.numberOfLines = 3;
    if (size.height < 65) {
        _m1_all.hidden = YES;
        [_m1_title mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(20);
            make.top.offset(20);
            make.right.offset(-26);
            make.bottom.offset(-20);
        }];
    }else{
        [_m1_title mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(20);
            make.top.offset(20);
            make.right.offset(-26);
        }];
        
        _m1_all.hidden = NO;
        if (unIntroduce) {
            _m1_title.numberOfLines = 0;
            [_m1_all setTitle:@"收起" forState:UIControlStateNormal];
        }else{
            _m1_title.numberOfLines = 3;
            [_m1_all setTitle:@"全文" forState:UIControlStateNormal];
        }
    }

}

- (void)m1_createUI{
    self.m1_title = [[UILabel alloc] init];
    _m1_title.text = @"我是一个很开朗的女孩，我喜欢到处去旅行，还喜 欢美食，我有和睦恩爱的父母，我的理想伴侣不一 定对我好，但我们要有共同的价值观";
    _m1_title.textColor = m1_color(0x333333);
    _m1_title.font = m1_font(15);
    _m1_title.numberOfLines = 0;
    [self.contentView addSubview:_m1_title];
    
    [_m1_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.offset(20);
        make.right.offset(-26);
    }];
    
    self.m1_all = [UIButton buttonWithType:UIButtonTypeCustom];
    [_m1_all setTitle:@"全文" forState:UIControlStateNormal];
    [_m1_all setTitleColor:m1_color(0xFF5A3F) forState:UIControlStateNormal];
    _m1_all.titleLabel.font = m1_font(14);
    [_m1_all addTarget:self action:@selector(m1_allAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:_m1_all];
    
    [_m1_all mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.m1_title.mas_bottom).offset(8);
        make.bottom.offset(5);
        make.right.offset(-10);
        make.size.mas_equalTo(CGSizeMake(48, 34));
    }];
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
